<template>
	<div>
		<el-autocomplete
			class="inline-input"
			style="width: 18rem;"
			v-model="inputValues"
			:fetch-suggestions="querySearch"
			:placeholder="placeholder"
			@select="handleSelect"
		></el-autocomplete>
	</div>
</template>

<script>
export default {
	name: '',
	props: {
		allInfos: {
			type: Array
		},
		placeholder: {
			type: String
		},
		inputValue: {
			type: String,
			default: ''
		}
	},
	data() {
		return {
			inputValues: this.inputValue
		};
	},
	created() {},
	methods: {
		querySearch(queryString, cb) {
			//处理数据为 {value:'值'} 格式 不然不生效
			let dimArr = [];
			this.allInfos.map(val => {
				let value =
					val.name ||
					val.number ||
					val.entry_name ||
					val.construction_unit ||
					val.name ||
					val.construction_unit ||
					val.drill_type ||
					val.minerals ||
					val.scale ||
					val.degree_of_work ||
					val.owner_unit ||
					val.owner_phone ||
					val.district;
				let id =
					val.id ||
					val.number ||
					val.entry_name ||
					val.construction_unit ||
					val.name ||
					val.construction_unit ||
					val.drill_type ||
					val.minerals ||
					val.scale ||
					val.degree_of_work ||
					val.owner_unit ||
					val.owner_phone ||
					val.district;
				dimArr.push({
					value,
					id
				});
			});
			var restaurants = dimArr;
			var results = queryString ? restaurants.filter(this.createFilter(queryString)) : restaurants;
			// 调用 callback 返回建议列表的数据
			cb(results);
		},
		createFilter(queryString) {
			return restaurant => {
				return restaurant.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0;
			};
		},
		//处理input模糊搜索
		handleSelect(item) {
			this.$emit('dimDepartment', item.id);
		}
	}
};
</script>

<style scoped></style>
